import vaex
import dask.dataframe as dd
import pandas as pd
import time


def clock(func):
    def inner(*args, **kwargs):
        start = time.time()
        res = func(*args, **kwargs)
        end = time.time()
        print(f'耗时:{end - start}')
        return res

    return inner


# df
@clock
def fun_df(file='AutoLoans.csv'):
    df = pd.read_csv(file)
    sum1 = df['id'].sum() + df['id'].mean() + df['id'].max() + df['id'].min() + df['id'].std()
    print(sum1)
    return sum1


# vaex
@clock
def fun_vaex(file='AutoLoans.csv'):
    vdf = vaex.open(file)
    sum2 = vdf.id.sum() + vdf.id.mean() + vdf.id.max() + vdf.id.min() + vdf.id.std()
    print(sum2)


# dask
@clock
def fun_dask(file='AutoLoans.csv'):
    ddf = dd.read_csv(file)
    sum3 = ddf.id.sum() + ddf.id.mean() + ddf.id.max() + ddf.id.min() + ddf.id.std()
    print(sum3.compute())


if __name__ == '__main__':
    file = 'AutoLoans5.csv'
    # df = pd.read_csv(file)
    # ddf = pd.concat([df for _ in range(100)])
    # ddf.to_csv('AutoLoans100.csv')
    fun_df(file)
    fun_vaex(file)
    fun_dask(file)
